#include <iostream>
#include <memory>
#include <cstring>
#include "tcp_sever.hpp"
#include "err.hpp"

using namespace std;
using namespace ns_sever;

using func_t= function<string(const string&)>;

static void usage(string s)
{
    cout<<"Usage\n\t"<<" "<<s<<"port\n"<<endl;
}

string echo(const string & message)
{
    return message;
}

// ./tcp_sever port 
int main(int argc,char * argv[])
{
    if(argc != 2)
    {
        // cerr<<"Usage error"<<strerror(errno)<<endl;
        usage(argv[0]);
        exit(USAGE_ERR);
    }
    
    uint16_t port=atoi(argv[1]);
    unique_ptr<TcpSever> uts(new TcpSever(echo,port));
    uts->init();
    uts->start();
    return 0;

}